package com.qkjia.day03;

import com.qkjia.day01.SleepUtils;

import java.util.concurrent.Semaphore;

public class Test05_Semaphore {
    public static void main(String[] args)  {
        Semaphore semaphore = new Semaphore(3);
        for (int i = 0; i <6 ; i++) {
            new Thread(()->{
                try {
                    //取得资格的意思
                    semaphore.acquire();
                    System.out.println(Thread.currentThread().getName()+"\t号车进入停车场");
                    SleepUtils.second(3);
                    System.out.println(Thread.currentThread().getName()+"\t号车驶出停车场");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } finally {
                    semaphore.release();
                }
            },""+i).start();
        }
    }
}
